// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

// 引入axios http
import axios from "axios";
// 引入qs处理请求的字符串数据
import qs from "qs";

// 添加请求拦截器
axios.interceptors.request.use(function (config) {
  // 使用qs处理http的处理方式
  config.data = qs.stringify(config.data);
  // 在发送请求之前做些什么
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  return response;
}, function (error) {
  // 对响应错误做点什么
  return Promise.reject(error);
});

// http请求方式封装
function request({
  method,
  url,
  params
}, customErr = false) {
  return new Promise((resolve, reject) => {
    axios({
      method: method,
      url: url,
      [method === "post" ?
        "data" :
        "params"
      ]: params
    }).then(response => {
      if (customErr) {
        resolve(response.data);
      } else {
        if (response.data.code === 0) {
          resolve(response.data.data);
        } else {

        }
      }
    }, error => {

      reject(error);
    }).catch(error => {

      reject(error);
    });
  });
}

Vue.prototype.$http = request;





Vue.config.productionTip = false
Vue.use(ElementUI);
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
})
